import urllib.request
import json
def getData(x):
    data = {"entpname": "公司",
        "certcode": "",
        "status":"有效",
        "startdate":"",
        "enddate":"",
        "page":x,
        "rows":"1000"}
    data_string=urllib.parse.urlencode(data)
    last_data=bytes(data_string,encoding='utf-8')
    f = urllib.request.urlopen("http://221.226.118.170:8080/entpcertlist/queryEntpCertList",data=last_data)
    j = json.loads(f.read().decode('utf-8'))
    ltp_data = json.dumps(j["rows"])
    return ltp_data
def saveDatas():
    for x in range(1,48):
        ltp_data = getData(x)
        def save(filename, contents):
              fh = open(filename, 'w', encoding='utf-8')
              fh.write(contents)
              fh.close()
        save(f'/Users/wangshuguan/江苏省/aa{x}.txt', ltp_data)

# saveDatas()

# print(getData(1))
# 
# datas = []
# for x in range(1,4):
#     with open(f'/Users/wangshuguan/aa{x}.txt') as f:
#         str = f.read()
#         j = json.loads(str)
#         for x1 in j:
#             datas.append(x1)
# companys = [x['corpname'] for x in datas]
# for x in companys:
# #     if x.find("公司") == -1 and  x.find("局") == -1 and  x.find("网") == -1 and  x.find("中心") == -1 and  x.find("院") == -1 and  x.find("平台") == -1 and  x.find("所") == -1 and  x.find("队") == -1 and  x.find("室") == -1 and  x.find("处") == -1 and  x.find("站") == -1 and  x.find("场") == -1 and  x.find("城") == -1 and  x.find("部") == -1 and  x.find("厂") == -1:
#     print(x)

